package com.example.managemyself.data.model;

import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.room.TypeConverters;

import com.example.managemyself.util.DateConverter;

import java.util.Date;

@Entity(tableName = "pomodoro_sessions")
public class PomodoroSession {
    @PrimaryKey(autoGenerate = true)
    private int id;
    
    private Date startTime;           // 开始时间
    private Date endTime;             // 结束时间
    private int workDurationMinutes;  // 工作时长（分钟）
    private int breakDurationMinutes; // 休息时长（分钟）
    private int completedPomodoros;   // 完成的番茄钟数量
    private String taskName;          // 关联的任务名称
    private int taskId;               // 关联的任务ID
    private boolean isCompleted;      // 是否完成
    private String notes;             // 备注
    
    // 构造函数
    public PomodoroSession(Date startTime, int workDurationMinutes, int breakDurationMinutes) {
        this.startTime = startTime;
        this.workDurationMinutes = workDurationMinutes;
        this.breakDurationMinutes = breakDurationMinutes;
        this.completedPomodoros = 0;
        this.isCompleted = false;
    }
    
    // Getters and Setters
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public Date getStartTime() {
        return startTime;
    }
    
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }
    
    public Date getEndTime() {
        return endTime;
    }
    
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
    
    public int getWorkDurationMinutes() {
        return workDurationMinutes;
    }
    
    public void setWorkDurationMinutes(int workDurationMinutes) {
        this.workDurationMinutes = workDurationMinutes;
    }
    
    public int getBreakDurationMinutes() {
        return breakDurationMinutes;
    }
    
    public void setBreakDurationMinutes(int breakDurationMinutes) {
        this.breakDurationMinutes = breakDurationMinutes;
    }
    
    public int getCompletedPomodoros() {
        return completedPomodoros;
    }
    
    public void setCompletedPomodoros(int completedPomodoros) {
        this.completedPomodoros = completedPomodoros;
    }
    
    public String getTaskName() {
        return taskName;
    }
    
    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }
    
    public int getTaskId() {
        return taskId;
    }
    
    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }
    
    public boolean isCompleted() {
        return isCompleted;
    }
    
    public void setCompleted(boolean completed) {
        isCompleted = completed;
    }
    
    public String getNotes() {
        return notes;
    }
    
    public void setNotes(String notes) {
        this.notes = notes;
    }
    
    // 计算总时长（分钟）
    public int getTotalDurationMinutes() {
        if (endTime != null && startTime != null) {
            return (int) ((endTime.getTime() - startTime.getTime()) / (60 * 1000));
        }
        return 0;
    }
    
    // 增加完成的番茄钟数量
    public void incrementCompletedPomodoros() {
        this.completedPomodoros++;
    }
}
